package varables;

/**
 * Author itcast
 * Date 2021/10/13 9:32
 * Desc TODO
 */
public class VierableDemo {
    public static void main(String[] args) {
        int compute = compute("*", 1, 2,3,4,5,6,7);
        System.out.println(compute);
    }
    //实现可变参数求和 两个参数 ：算符运算符  和  可变参数-每个值
    public static int compute(String ch,int... arr){
        //遍历出来每个值
        int sum = 0;
        for (int i : arr) {
            //判断是 + - / *
            switch(ch){
                case "+":
                    sum += i;
                    break;
                case "-":
                    sum -= i;
                    break;
                case "*":
                    if(sum==0){
                        sum=1;
                    }
                    sum *=i;
                    break;
                case "/":
                    if(sum==0){
                        sum=1;
                    }
                    sum /=i;
                    break;
            }
        }
        return sum;
    }
}
